package androidx.fragment.app;

import android.animation.Animator;
import android.animation.AnimatorInflater;
import android.animation.AnimatorListenerAdapter;
import android.content.Context;
import android.content.res.Resources;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.AnimationUtils;
import android.view.animation.Transformation;
import androidx.fragment.app.v;
import b.f.h.a;
import b.f.l.p;

class e {

    static class a implements a.C0036a {

        /* renamed from: a  reason: collision with root package name */
        final /* synthetic */ Fragment f600a;

        a(Fragment fragment) {
            this.f600a = fragment;
        }

        public void a() {
            if (this.f600a.getAnimatingAway() != null) {
                View animatingAway = this.f600a.getAnimatingAway();
                this.f600a.setAnimatingAway((View) null);
                animatingAway.clearAnimation();
            }
            this.f600a.setAnimator((Animator) null);
        }
    }

    static class b implements Animation.AnimationListener {

        /* renamed from: a  reason: collision with root package name */
        final /* synthetic */ ViewGroup f601a;

        /* renamed from: b  reason: collision with root package name */
        final /* synthetic */ Fragment f602b;

        /* renamed from: c  reason: collision with root package name */
        final /* synthetic */ v.g f603c;

        /* renamed from: d  reason: collision with root package name */
        final /* synthetic */ b.f.h.a f604d;

        class a implements Runnable {
            a() {
            }

            public void run() {
                if (b.this.f602b.getAnimatingAway() != null) {
                    b.this.f602b.setAnimatingAway((View) null);
                    b bVar = b.this;
                    bVar.f603c.a(bVar.f602b, bVar.f604d);
                }
            }
        }

        b(ViewGroup viewGroup, Fragment fragment, v.g gVar, b.f.h.a aVar) {
            this.f601a = viewGroup;
            this.f602b = fragment;
            this.f603c = gVar;
            this.f604d = aVar;
        }

        public void onAnimationEnd(Animation animation) {
            this.f601a.post(new a());
        }

        public void onAnimationRepeat(Animation animation) {
        }

        public void onAnimationStart(Animation animation) {
        }
    }

    static class c extends AnimatorListenerAdapter {

        /* renamed from: a  reason: collision with root package name */
        final /* synthetic */ ViewGroup f606a;

        /* renamed from: b  reason: collision with root package name */
        final /* synthetic */ View f607b;

        /* renamed from: c  reason: collision with root package name */
        final /* synthetic */ Fragment f608c;

        /* renamed from: d  reason: collision with root package name */
        final /* synthetic */ v.g f609d;
        final /* synthetic */ b.f.h.a e;

        c(ViewGroup viewGroup, View view, Fragment fragment, v.g gVar, b.f.h.a aVar) {
            this.f606a = viewGroup;
            this.f607b = view;
            this.f608c = fragment;
            this.f609d = gVar;
            this.e = aVar;
        }

        public void onAnimationEnd(Animator animator) {
            this.f606a.endViewTransition(this.f607b);
            Animator animator2 = this.f608c.getAnimator();
            this.f608c.setAnimator((Animator) null);
            if (animator2 != null && this.f606a.indexOfChild(this.f607b) < 0) {
                this.f609d.a(this.f608c, this.e);
            }
        }
    }

    static class d {

        /* renamed from: a  reason: collision with root package name */
        public final Animation f610a;

        /* renamed from: b  reason: collision with root package name */
        public final Animator f611b;

        d(Animator animator) {
            this.f610a = null;
            this.f611b = animator;
            if (animator == null) {
                throw new IllegalStateException("Animator cannot be null");
            }
        }

        d(Animation animation) {
            this.f610a = animation;
            this.f611b = null;
            if (animation == null) {
                throw new IllegalStateException("Animation cannot be null");
            }
        }
    }

    /* renamed from: androidx.fragment.app.e$e  reason: collision with other inner class name */
    private static class C0017e extends AnimationSet implements Runnable {

        /* renamed from: b  reason: collision with root package name */
        private final ViewGroup f612b;

        /* renamed from: c  reason: collision with root package name */
        private final View f613c;

        /* renamed from: d  reason: collision with root package name */
        private boolean f614d;
        private boolean e;
        private boolean f = true;

        C0017e(Animation animation, ViewGroup viewGroup, View view) {
            super(false);
            this.f612b = viewGroup;
            this.f613c = view;
            addAnimation(animation);
            this.f612b.post(this);
        }

        public boolean getTransformation(long j, Transformation transformation) {
            this.f = true;
            if (this.f614d) {
                return !this.e;
            }
            if (!super.getTransformation(j, transformation)) {
                this.f614d = true;
                p.a(this.f612b, this);
            }
            return true;
        }

        public boolean getTransformation(long j, Transformation transformation, float f2) {
            this.f = true;
            if (this.f614d) {
                return !this.e;
            }
            if (!super.getTransformation(j, transformation, f2)) {
                this.f614d = true;
                p.a(this.f612b, this);
            }
            return true;
        }

        public void run() {
            if (this.f614d || !this.f) {
                this.f612b.endViewTransition(this.f613c);
                this.e = true;
                return;
            }
            this.f = false;
            this.f612b.post(this);
        }
    }

    static void a(Fragment fragment, d dVar, v.g gVar) {
        View view = fragment.mView;
        ViewGroup viewGroup = fragment.mContainer;
        viewGroup.startViewTransition(view);
        b.f.h.a aVar = new b.f.h.a();
        aVar.c(new a(fragment));
        gVar.b(fragment, aVar);
        if (dVar.f610a != null) {
            C0017e eVar = new C0017e(dVar.f610a, viewGroup, view);
            fragment.setAnimatingAway(fragment.mView);
            eVar.setAnimationListener(new b(viewGroup, fragment, gVar, aVar));
            fragment.mView.startAnimation(eVar);
            return;
        }
        Animator animator = dVar.f611b;
        fragment.setAnimator(animator);
        animator.addListener(new c(viewGroup, view, fragment, gVar, aVar));
        animator.setTarget(fragment.mView);
        animator.start();
    }

    static d b(Context context, f fVar, Fragment fragment, boolean z) {
        int c2;
        int nextTransition = fragment.getNextTransition();
        int nextAnim = fragment.getNextAnim();
        boolean z2 = false;
        fragment.setNextAnim(0);
        View c3 = fVar.c(fragment.mContainerId);
        if (!(c3 == null || c3.getTag(b.i.b.visible_removing_fragment_view_tag) == null)) {
            c3.setTag(b.i.b.visible_removing_fragment_view_tag, (Object) null);
        }
        ViewGroup viewGroup = fragment.mContainer;
        if (viewGroup != null && viewGroup.getLayoutTransition() != null) {
            return null;
        }
        Animation onCreateAnimation = fragment.onCreateAnimation(nextTransition, z, nextAnim);
        if (onCreateAnimation != null) {
            return new d(onCreateAnimation);
        }
        Animator onCreateAnimator = fragment.onCreateAnimator(nextTransition, z, nextAnim);
        if (onCreateAnimator != null) {
            return new d(onCreateAnimator);
        }
        if (nextAnim != 0) {
            boolean equals = "anim".equals(context.getResources().getResourceTypeName(nextAnim));
            if (equals) {
                try {
                    Animation loadAnimation = AnimationUtils.loadAnimation(context, nextAnim);
                    if (loadAnimation != null) {
                        return new d(loadAnimation);
                    }
                    z2 = true;
                } catch (Resources.NotFoundException e) {
                    throw e;
                } catch (RuntimeException unused) {
                }
            }
            if (!z2) {
                try {
                    Animator loadAnimator = AnimatorInflater.loadAnimator(context, nextAnim);
                    if (loadAnimator != null) {
                        return new d(loadAnimator);
                    }
                } catch (RuntimeException e2) {
                    if (!equals) {
                        Animation loadAnimation2 = AnimationUtils.loadAnimation(context, nextAnim);
                        if (loadAnimation2 != null) {
                            return new d(loadAnimation2);
                        }
                    } else {
                        throw e2;
                    }
                }
            }
        }
        if (nextTransition != 0 && (c2 = c(nextTransition, z)) >= 0) {
            return new d(AnimationUtils.loadAnimation(context, c2));
        }
        return null;
    }

    private static int c(int i, boolean z) {
        if (i == 4097) {
            return z ? b.i.a.fragment_open_enter : b.i.a.fragment_open_exit;
        }
        if (i == 4099) {
            return z ? b.i.a.fragment_fade_enter : b.i.a.fragment_fade_exit;
        }
        if (i != 8194) {
            return -1;
        }
        return z ? b.i.a.fragment_close_enter : b.i.a.fragment_close_exit;
    }
}
